import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';
import { stringFormat } from '/@/utils/common/compUtils';

enum Api {
  list = '/api-iot/iot/collectTask/list',
  save = '/api-iot/iot/collectTask/saveOrUpdate',
  edit = '/api-iot/iot/collectTask/saveOrUpdate',
  delete = '/api-iot/iot/collectTask/delete',
  deleteBatch = '/api-iot/iot/collectTask/deleteBatch',
  queryById = '/api-iot/iot/collectTask/queryById',
  status = '/api-iot/iot/collectTask/status',
  collectActions = '/api-iot/iot/collectTask/collectActions',
  storeActions = '/api-iot/iot/collectTask/storeActions',
}

/**
 * 列表接口-分页
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 删除采集任务
 * @param params 
 * @param handleSuccess 
 * @returns 
 */
export const deleteCollectTask = (params, handleSuccess) => {
return defHttp.delete({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {
  handleSuccess();
});
};


/**
 * 批量删除采集任务
 * @param params
 */
export const batchDeleteCollectTask = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 保存或者更新采集任务
 * @param params
 */
export const saveOrUpdateCollectTask = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 查询采集任务-ID
 * @param params
 */
export const getCollectTaskById = (params) => {
  return defHttp.get({ url: Api.queryById, params });
};

/**
 * 切换采集任务状态
 * @param params
 */
export const switchStatus = (params) => {
  return defHttp.post({ url: Api.status, params });
};

/**
 * 采集动作
 * @param params
 */
export const getCollectActions = (params) => {
  return defHttp.get({ url: Api.collectActions, params });
};

/**
 * 存储动作
 * @param params
 */
export const getStoreActions = (params) => {
  return defHttp.get({ url: Api.storeActions, params });
};